/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *  http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.wicketstuff.js.ext;

import org.wicketstuff.js.ext.util.ExtClass;
import org.wicketstuff.js.ext.util.ExtProperty;
import org.wicketstuff.js.ext.util.ExtResizable;

@ExtClass("Ext.Window")
public class ExtWindow extends ExtPanel {

    public enum CloseAction {
        CLOSE, HIDE
    }

    @ExtProperty
    protected Boolean closeable;
    @ExtProperty
    protected CloseAction closeAction;
    @ExtProperty
    protected Boolean collapsed;
    @ExtProperty
    protected Boolean constrain;
    @ExtProperty
    protected Boolean constrainHeader;
    @ExtProperty
    protected Boolean draggable;
    @ExtProperty
    protected Boolean expandOnShow;
    // sets visibility on dom basis
    protected Boolean hidden;
    @ExtProperty
    protected Boolean initHidden;
    @ExtProperty
    protected Boolean maximizable;
    @ExtProperty
    protected Boolean maximized;
    @ExtProperty
    protected Number minHeight;
    @ExtProperty
    protected Number minWidth;
    @ExtProperty
    protected Boolean minimizable;
    @ExtProperty
    protected Boolean modal;
    @ExtProperty
    protected Boolean plain;
    @ExtProperty
    protected Boolean resizable;
    @ExtProperty
    protected ExtResizable resizeHandles;
    @ExtProperty
    protected Number x;
    @ExtProperty
    protected Number y;

    public ExtWindow(String id) {
        super(id);
    }

    @Override
    protected boolean isRenderFromMarkup() {
        return false;
    }

    @Override
    protected String getName() {
        return "x-window";
    }

    public void setCloseable(Boolean closeable) {
        this.closeable = closeable;
    }

    public void setCloseAction(CloseAction closeAction) {
        this.closeAction = closeAction;
    }

    public void setCollapsed(Boolean collapsed) {
        this.collapsed = collapsed;
    }

    public void setConstrain(Boolean constrain) {
        this.constrain = constrain;
    }

    public void setConstrainHeader(Boolean constrainHeader) {
        this.constrainHeader = constrainHeader;
    }

    public void setDraggable(Boolean draggable) {
        this.draggable = draggable;
    }

    public void setExpandOnShow(Boolean expandOnShow) {
        this.expandOnShow = expandOnShow;
    }

    public void setHidden(Boolean hidden) {
        if (hidden) {
            hide();
        } else {
            show();
        }
    }

    public void setInitHidden(Boolean initHidden) {
        this.initHidden = initHidden;
    }

    public void setMaximizable(Boolean maximizable) {
        this.maximizable = maximizable;
    }

    public void setMaximized(Boolean maximized) {
        if (maximized) {
            maximize();
        } else {
            minimize();
        }
    }

    public void setMinHeight(Number minHeight) {
        this.minHeight = minHeight;
    }

    public void setMinWidth(Number minWidth) {
        this.minWidth = minWidth;
    }

    public void setMinimizable(Boolean minimizable) {
        this.minimizable = minimizable;
    }

    public void setModal(Boolean modal) {
        this.modal = modal;
    }

    public void setPlain(Boolean plain) {
        this.plain = plain;
    }

    public void setResizeable(Boolean resizeable) {
        this.resizable = resizeable;
    }

    public void setResizeHandles(ExtResizable resizeHandles) {
        this.resizeHandles = resizeHandles;
    }

    public void setX(Number x) {
        this.x = x;
    }

    public void setY(Number y) {
        this.y = y;
    }

    public void toggleMaximize() {
        if (maximized) {
            restore();
        } else {
            maximize();
        }
    }

    public void center() {
    }

    public void close() {
    }

    public void focus() {
    }

    public void hide() {
        hidden = true;
    }

    public void maximize() {
        maximized = true;
    }

    public void minimize() {
        maximized = false;
    }

    public void restore() {
        maximized = false;
    }

    public void setActive(Boolean active) {
    }

    public void show() {
        hidden = false;
    }

    public void toBack() {
    }

    public void toFront() {
    }

}
